<template>
  <!-- 项目详细信息 -->
  <div class="detail-container">
    <el-page-header content="项目详情" style="  margin-bottom: 40px;" @back="goback" />
    <!-- 项目基本信息 -->
    <div>
      <div class="info-container">
        <span class="info-span">项目基本信息</span>
        <el-divider />
      </div>
      <el-form
        ref="basic"
        :model="basic"
        style="margin-left: 10%"
      >
        <el-form-item label="名称:" style="height: 30px">{{ basic.name }}</el-form-item>
        <el-form-item label="发布时间:" style="height: 30px">{{ basic.reltime }}</el-form-item>
        <el-form-item label="描述:" style="height: 30px">
          <p v-html="basic.maintext">
            {{ basic.maintext }}
          </p>
        </el-form-item>
        <el-form-item label="附件:" style="height: 30px">
          <el-link type="info" size="mini" style="margin-left: 30px" @click="handleDownloadProInfo">
            点击下载
          </el-link>
        </el-form-item>
        <el-form-item label="教师评分:" style="height: 30px">{{ basic.score === 0 ? '暂未评分' : basic.score }}</el-form-item>
        <el-form-item label="教师评语:">
          <p style="margin-top: 0px">
            {{ basic.comment === '' ? '暂无评语' : basic.comment }}
          </p>
        </el-form-item>
      </el-form>
    </div>
    <!-- 项目成员信息 -->
    <div class="user-container">
      <div class="info-container">
        <span class="info-span">项目成员</span>
        <el-divider />
      </div>
      <!-- <el-table
        :data="userList"
        style="margin-left: 14%; width: 800px"
      >
        <el-table-column label="姓名" min-width="30%" align="center">
          <template slot-scope="scope">
            {{ scope.row.name }}
          </template>
        </el-table-column>
        <el-table-column label="角色" min-width="50%" align="center">
          <template slot-scope="scope">
            {{ scope.row.role }}
          </template>
        </el-table-column>
      </el-table> -->

      <!-- 用原生table实现尝试 -->
      <el-card>
        <!-- <div
          v-for="(item) in userList"
          :key="item"
        >
          {{ item.name }} {{ item.role }}
        </div> -->
        <el-table
          :data="userList"
        >
          <el-table-column label="姓名" min-width="30%" align="center">
            <template slot-scope="scope">
              {{ scope.row.name }}
            </template>
          </el-table-column>

          <el-table-column label="角色" align="center">
            <template slot-scope="scope">
              {{ scope.row.role }}
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>
    <!-- 项目动态 -->
    <div>
      <div class="info-container">
        <span class="info-span">项目动态</span>
        <el-divider />
      </div>
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in progressList"
          :key="index"
          size="large"
          :timestamp="item.reltime"
          placement="top"
        >
          <el-card style="width: 80%">
            <h4>由{{ item.reluser }}发布</h4>
            <p v-html="item.maintext">{{ item.maintext }}</p>
            <div v-show="item.attachment !== ''">
              <span>
                附件:
                <el-link type="info" @click="handleDownloadProgressFile(item.attachment)">
                  点击下载
                </el-link>
              </span>
            </div>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </div>
  </div>
</template>

<script>
import { getDetail, downloadProFile, downloadProgressFile } from '@/api/project'
import { downloadAttachs } from '@/utils/download'

export default {
  name: 'Detail',
  data() {
    return {
      basic: {
        name: '',
        reltime: '',
        maintext: '',
        score: 0,
        comment: ''
      },
      userList: null,
      progressList: null
    }
  },
  created() {
    // const id = this.$route.params && this.$route.params.id
    const id = window.localStorage.getItem('detail_id')
    this.fetchData(id)
  },
  methods: {
    fetchData(id) {
      getDetail(id).then(res => {
        this.basic = res.data.basic
        this.userList = res.data.userList
        this.progressList = res.data.progressList
      })
    },
    // 项目基本信息下载
    handleDownloadProInfo() {
      downloadProFile(window.localStorage.getItem('detail_id')).then(res => {
        downloadAttachs(res)
        this.$message({
          message: '附件下载成功',
          type: 'success'
        })
      })
    },
    handleDownloadProgressFile(path) {
      downloadProgressFile(path).then(res => {
        downloadAttachs(res)
        this.$message({
          message: '项目动态附件下载成功',
          type: 'success'
        })
      })
    },
    // 页头返回
    goback() {
      const from = window.localStorage.getItem('from')
      console.log('from===' + from)
      if (from === 'work') {
        this.$router.push('/work/list')
      }
      if (from === 'project') {
        this.$router.push('/project/list')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.detail-container {
  padding: 50px;
}
.user-container {
  width: 100%;
}
.info-container {
  .info-span {
    margin-left: 10px;
  }

  margin-top: 20px;
  font-family: Arial;
  font-weight: 700;
  font-size: 20px;
  color: rgb(95, 200, 204);
}
</style>
